﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows;
using RouteTiming.Data;
using RouteTiming.SLClient.DynamicModel;

//using RouteTiming.SLClient.DynamicModel;

namespace RouteTiming.SLClient
{
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using System.ServiceModel.DomainServices.Client;
    using RouteTiming.SLClient.Web;

    /// <summary>
    /// Home page for the application.
    /// </summary>
    public partial class Home : Page
    {
//        private RouteTimingDomainContext _context = new RouteTimingDomainContext();
//        private Int64 _lastEventOrderNo;

//        private DynamicContext _context;

        /// <summary>
        /// Creates a new <see cref="Home"/> instance.
        /// </summary>
        public Home()
        {
            InitializeComponent();

            this.Title = ApplicationStrings.HomePageTitle;
        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                new Thread(() =>
                               {
                                   Thread.Sleep(1000);
                                   throw new Exception("Thread fail...");
                                   
                               }).Start();


//                if (this._context == null)
//                    this._context = new DynamicContext();

//                var cls = new Class1();

//                cls.Test();

//                this.dataGrid1.ItemsSource = _context.Routes;

//                _context.Load( _context.GetRouteSetQuery());


//                this._context.GetNewEvents(_lastEventOrderNo, OnNewEvents, null);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void DynamicContext_OnError(object sender, DynamicModel.Helpers.OnErrorEventArgs e)
        {
            ErrorWindow.CreateNew(e.Message);
        }

        private void DynamicContext_OnWarning(object sender, DynamicModel.Helpers.OnWarningEventArgs e)
        {
            this.txtWarning.Text = e.Message;
        }

        private void DynamicContext_OnOperationCancelled(object sender, EventArgs e)
        {
            this.txtWarning.Text = "Operation was cancelled!";
        }
    }
}